﻿using System;
using System.Linq;

namespace Dpy.Math.Geometry.Geometry2D
{
    public static class Intersector2D
    {
        /// <summary>
        /// Intersects two lines.
        /// </summary>
        /// <param name="a">The first line.</param>
        /// <param name="b">The second line.</param>
        /// <param name="lineCoordinateOnA">The coordinate on line a. If two lines coincide lineCoodinateOnA is PositiveInfinity.</param>
        /// <param name="lineCoordinateOnB">The coordinate on line b. If two lines coincide lineCoodinateOnB is PositiveInfinity.</param>
        /// <returns>The intersection point. If two lines are parallel or coincide returns null.</returns>
        public static Vector2D Intersect(Line2D a, Line2D b, out double lineCoordinateOnA, out double lineCoordinateOnB)
        {
            return Line2D.Intersect(a, b, out lineCoordinateOnA, out lineCoordinateOnB);
        }

        public static Vector2D Intersect(Line2D line, Ray2D ray, out double lineCoordinate, out double rayCoordinate)
        {
            return ray.IntersectWith(line, out rayCoordinate, out lineCoordinate);
        }

        public static Vector2D Intersect(Ray2D ray, Line2D line, out double lineCoordinate, out double rayCoordinate)
        {
            return ray.IntersectWith(line, out rayCoordinate, out lineCoordinate);
        }

        public static Vector2D Intersect(Ray2D a, Ray2D b, out double rayCoordinateOnA, out double rayCoordinateOnB)
        {
            return Ray2D.Intersect(a, b, out rayCoordinateOnA, out rayCoordinateOnB);
        }

        public static Vector2D Intersect(LineSegment2D a, LineSegment2D b, out double segmentCoordinateOnA, out double segmentCoordinateOnB)
        {
            return LineSegment2D.Intersect(a, b, out segmentCoordinateOnA, out segmentCoordinateOnB);
        }

        public static Vector2D Intersect(LineSegment2D lineSegment, Ray2D ray, out double segmentCoordinate, out double rayCoordinate)
        {
            return lineSegment.IntersectWith(ray, out segmentCoordinate, out rayCoordinate);
        }

        public static Vector2D Intersect(Ray2D ray, LineSegment2D lineSegment, out double segmentCoordinate, out double rayCoordinate)
        {
            return lineSegment.IntersectWith(ray, out segmentCoordinate, out rayCoordinate);
        }

        public static Vector2D Intersect(LineSegment2D lineSegment, Line2D line, out double segmentCoordinate, out double lineCoordinate)
        {
            return lineSegment.IntersectWith(line, out segmentCoordinate, out lineCoordinate);
        }

        public static Vector2D Intersect(Line2D line, LineSegment2D lineSegment, out double segmentCoordinate, out double lineCoordinate)
        {
            return lineSegment.IntersectWith(line, out segmentCoordinate, out lineCoordinate);
        }

        public static Vector2D[] Intersect(Line2D line, Circle circle, out double[] lineCoordinates)
        {
            return line.IntersectWith(circle, out lineCoordinates);
        }

        public static Vector2D[] Intersect(Circle circle, Line2D line, out double[] lineCoordinates)
        {
            return line.IntersectWith(circle, out lineCoordinates);
        }

        public static Vector2D[] Intersect(LineSegment2D lineSegment, Circle circle, out double[] segmentCoordinates)
        {
            return lineSegment.IntersectWith(circle, out segmentCoordinates);
        }

        public static Vector2D[] Intersect(Circle circle, LineSegment2D lineSegment, out double[] segmentCoordinates)
        {
            return lineSegment.IntersectWith(circle, out segmentCoordinates);
        }

        public static Vector2D[] Intersect(Ray2D ray, Circle circle, out double[] rayCoordinates)
        {
            return ray.IntersectWith(circle, out rayCoordinates);
        }

        public static Vector2D[] Intersect(Circle circle, Ray2D ray, out double[] rayCoordinates)
        {
            return ray.IntersectWith(circle, out rayCoordinates);
        }
    }
}
